package es.usj.apps.moviles;

import java.util.HashMap;
import java.util.Map.Entry;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import es.usj.apps.moviles.parsers.ParserJSON;
import es.usj.apps.moviles.parsers.ParserJSON.OnParserJSONListener;
import es.usj.apps.moviles.parsers.WsResult;

public class MapActivity extends Activity implements OnParserJSONListener {

	private static final String url = "http://app.wicip.ca/smartauto/nearestChargeStations.php?latitude=41.63801699375&longitude=-0.8705257337500143";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.map_layout);

		ParserJSON parser = new ParserJSON();
		parser.setOnParserJSONListener(this);
		parser.startConnection(url);
	}

	@Override
	public void onParserJSONResult(WsResult<?> result) {

		if (result == null) {
			Log.e("Electric-vehicle", "objeto vacio");
		} else {
			for (int i = 0; i < result.getLength(); i++) {
				@SuppressWarnings("unchecked")
				HashMap<String, String> object = (HashMap<String, String>) result
						.getObject(i);

				// Recorremos el HashMap que contiene el JSON parseado
				for (Entry<String, String> entry : object.entrySet()) {
					System.out.println("Key: " + entry.getKey().toString()
							+ " / Value: " + entry.getValue());
				}
			}
		}
	}
}
